<template>
    <div id="dr31">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>商家管理</BreadcrumbItem>
            <BreadcrumbItem>店铺纠错</BreadcrumbItem>
        </Breadcrumb>
        <Input v-model="selectMobile" placeholder="查询手机号码" style="width: 150px"/>
        &nbsp;
        <Button type="info" @click="search()">查询</Button>
        <Table :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0" style="margin-top: 10px" @on-row-dblclick="rowData"></Table>

        <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
              style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
              v-if="data&&data.length>0"/>
        <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
            总计 {{pageTotal}} 条数据
        </div>
        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>
        <Modal v-model="dealwith">
            <p slot="header" style="color:#444;text-align:center">
                <span>选择处理结果</span>
            </p>
            <div style="text-align:left;font-size: 16px;">
                <div>
                    <div>角色类型:&nbsp;{{typeName}}</div>
                    <div>注册电话号码:&nbsp;{{zucePhone}}</div>
                    <div v-if="phone1">使用号码1:&nbsp;{{phone1}}</div>
                    <div v-if="phone2">使用号码1:&nbsp;{{phone2}}</div>
                    <div v-if="phone3">使用号码1:&nbsp;{{phone3}}</div>
                </div>


                <RadioGroup v-model="radioStr">

                    <Radio label="未处理" style=" font-size: 18px;padding: 2px"></Radio>
                    <br>
                    <Radio label="已处理" style=" font-size: 18px;padding: 2px"></Radio>
                    <br>
                </RadioGroup>
            </div>
            <div slot="footer">
                <Button type="info" @click="dealwith=false">取消</Button>
                <Button type="info" @click="dealWithData()">确认</Button>
            </div>
        </Modal>
    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';
    export default{
        data(){
            return {
                typeName: "",
                id: "",
                zucePhone: "",
                phone1: "",
                phone2: "",
                phone3: "",
                selectMobile: "",
                companyId: "",
                radioStr: "未处理",
                loading: false,
                dealwith: false,
                index: 0,
                pageTotal: 0,
                shopMobile: '',
                curPage: 0,
                columns: [
                    {
                        title: '纠错时间',
                        key: 'createTime1',
                        width: 150
                    },
                    {
                        title: '纠错人手机号码',
                        key: 'toMobile',
                        width: 120
                    },
                    {
                        title: '处理结果',
                        key: 'isHandle1'
                    }, {
                        title: '纠错原因',
                        key: 'reason1'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    }, style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.companyId = params.row.companyId;
                                            this.id = params.row._id;
                                            this.index = params.index;
                                            this.getCompanyData();
                                        }
                                    }
                                }, '处理')
                            ]);
                        }
                    }
                ],
                data: []
            }
        },
        mounted(){
            this.getData();
        },
        methods: {
            typeChange(){
                this.getData();
            },
            pageChange(page){
                this.getData(page);
            },
            rowData(data, index){

            },
            search(){
                this.getData();
            },
            dealWithData(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('errorId', this.id);

                if (this.radioStr == '未处理') {
                    param.append('isHandle', "0");
                }
                if (this.radioStr == '已处理') {
                    param.append('isHandle', "1");
                }
                this.loading = true;
                Axios.post(ipServer + "usercompany/handle", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                if (this.radioStr == '未处理') {
                                    this.data[this.index].isHandle = 0;
                                    this.data[this.index].isHandle1 = '未处理';
                                }
                                if (this.radioStr == '已处理') {
                                    this.data[this.index].isHandle = 1;
                                    this.data[this.index].isHandle1 = '已处理';
                                }

                                this.$Message.info("处理成功!");
                                this.radioStr == '未处理'
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                            this.dealwith = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            getCompanyData(){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('companyId', this.companyId);

                console.log("打印店铺ID" + this.companyId)
                this.loading = true;
                Axios.post(ipServer + "usercompany/selectShopsDetailById", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);
                                this.zucePhone = res.data.data.userMobile;
                                this.phone1 = res.data.data.mobile;
                                this.phone2 = res.data.data.mobile2;
                                this.phone3 = res.data.data.mobile3;

                                if (res.data.data.userType == "1") {
                                    this.typeName = "司机";
                                }
                                if (res.data.data.userType == "2") {
                                    this.typeName = "配件商";
                                }
                                if (res.data.data.userType == "3") {
                                    this.typeName = "修理";
                                }
                                if (res.data.data.userType == "4") {
                                    this.typeName = "补胎";
                                }
                                if (res.data.data.userType == "5") {
                                    this.typeName = "审车";
                                }
                                if (res.data.data.userType == "6") {
                                    this.typeName = "加油";
                                }
                                if (res.data.data.userType == "7") {
                                    this.typeName = "吊车";
                                }

                                this.dealwith = true;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$Message.info(res.data.msg);
                                this.$router.push("/login");
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;

                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            },
            getData(page){
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('userType', this.type);
                if (page) {
                    param.append('pageId', page + "");
                }
                if (this.selectMobile) {
                    param.append('shopMobile', this.selectMobile + "");
                }
                this.loading = true;
                Axios.post(ipServer + "usercompany/selectErrorShops", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                console.log("打印数" + JSON.stringify(res));
                                sessionUtils.setSession("token", res.data.token);
                                for (var i = 0; i < res.data.data.result.length; i++) {
                                    res.data.data.result[i].createTime1 = sessionUtils.timestampToTime(res.data.data.result[i].createTime);

                                    if (res.data.data.result[i].isHandle == 0) {
                                        res.data.data.result[i].isHandle1 = "未处理";
                                    } else {
                                        res.data.data.result[i].isHandle1 = "已处理";
                                    }

                                    if (res.data.data.result[i].reason == 1) {
                                        res.data.data.result[i].reason1 = "联系电话有误!"
                                    }
                                    if (res.data.data.result[i].reason == 2) {
                                        res.data.data.result[i].reason1 = "为店铺不存在!"
                                    }
                                    if (res.data.data.result[i].reason == 3) {
                                        res.data.data.result[i].reason1 = "为店铺己搬迁!"
                                    }
                                    if (res.data.data.result[i].reason == 4) {
                                        res.data.data.result[i].reason1 = "服务品牌变更!"
                                    }
                                    if (res.data.data.result[i].reason == 5) {
                                        res.data.data.result[i].reason1 = "商家己改行!"
                                    }
                                    if (res.data.data.result[i].reason == 6) {
                                        res.data.data.result[i].reason1 = res.data.data.result[i].remark;
                                    }
                                    if (res.data.data.result[i].reason == 7) {
                                        res.data.data.result[i].reason1 = "不能修货车!"
                                    }
                                }


                                this.data = res.data.data.result;
                                this.pageTotal = res.data.data.dataTotal;
                                this.curPage = res.data.data.curPage;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);
                            } else {
                                this.$Message.info(res.data.msg);
                            }
                            this.loading = false;
                        })
                        .catch(err=> {
                            this.loading = false;
                            this.$Message.info(err);
                        });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>